package com.tj.bo.trade.server.service.rule;

import com.tj.bo.trade.server.entity.bussiness.TradeDispersionEntity;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 黄金: 净利润小于0
 * 黄金: 每日交易金额的离散系数小于0.5
 * Author: Amarendar
 * Date: 2020/8/25 下午3:11
 */
@Service
public class TradeGoldRule1 extends BaseTradeRule {

    private static final String RULE_NAME = "净利润小于0";

    private static final Integer DEFAULT_PRIORITY = 5;

    @Override
    public void checkRouterRule(RouterContext routerContext, List<RuleResultVO> ruleResultVOList) {

        TradeDispersionEntity tradeDispersionEntity = binaryTradeDao.selectTradeDispersion(routerContext.getUserCode(), routerContext.getProductCode());
        if (tradeDispersionEntity == null || tradeDispersionEntity.getTotalOrderNum() < redisConfigUtil.getChangeOddsUserTradeNumbers()) {
            ruleResultVOList.add(new RuleResultVO(routerContext.getProductCode(), RULE_NAME).setMessage("订单数过少"));
            return;
        }

        if (tradeDispersionEntity.getUserProfit().doubleValue() < 0) {
            RuleResultVO ruleResultVO = new RuleResultVO(routerContext.getProductCode(), RULE_NAME);
            ruleResultVO.setPriority(DEFAULT_PRIORITY);
            ruleResultVO.setMode(0);
            ruleResultVO.setChangeValue(BigDecimal.ZERO);
            ruleResultVO.setMessage("净利润小于0");
            ruleResultVOList.add(ruleResultVO);
        } else if (tradeDispersionEntity.getCoefficient() < 0.5) {
            RuleResultVO ruleResultVO = new RuleResultVO(routerContext.getProductCode(), "每日交易金额的离散系数小于0.5");
            ruleResultVO.setPriority(DEFAULT_PRIORITY);
            ruleResultVO.setMode(0);
            ruleResultVO.setChangeValue(BigDecimal.ZERO);
            ruleResultVO.setMessage("每日交易金额的离散系数小于0.5");
            ruleResultVOList.add(ruleResultVO);
        } else {
            ruleResultVOList.add(new RuleResultVO(routerContext.getProductCode(), RULE_NAME).setMessage("净利润小于0/每日交易金额的离散系数小于0.5-条件不满足"));
        }

    }
}
